from tortoise import BaseDBAsyncClient

RUN_IN_TRANSACTION = True


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `users` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '用户ID',
    `username` VARCHAR(50) NOT NULL UNIQUE COMMENT '用户名',
    `email` VARCHAR(100) NOT NULL UNIQUE COMMENT '邮箱',
    `password` VARCHAR(100) NOT NULL COMMENT '密码',
    `created_at` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)
) CHARACTER SET utf8mb4 COMMENT='用户表';
CREATE TABLE IF NOT EXISTS `dingtalk_users` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID',
    `unionid` VARCHAR(50) NOT NULL UNIQUE COMMENT '钉钉用户唯一标识',
    `openid` VARCHAR(50) NOT NULL UNIQUE COMMENT '钉钉用户开放ID',
    `nickname` VARCHAR(100) COMMENT '用户昵称',
    `avatar_url` LONGTEXT COMMENT '用户头像URL',
    `access_token` LONGTEXT NOT NULL COMMENT '访问令牌',
    `refresh_token` LONGTEXT NOT NULL COMMENT '刷新令牌',
    `expire_at` DATETIME(6) NOT NULL COMMENT '访问令牌过期时间',
    `created_at` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `user_id` INT COMMENT '关联的本地用户',
    CONSTRAINT `fk_dingtalk_users_c706cdca` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COMMENT='钉钉用户表';
CREATE TABLE IF NOT EXISTS `aerich` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `version` VARCHAR(255) NOT NULL,
    `app` VARCHAR(100) NOT NULL,
    `content` JSON NOT NULL
) CHARACTER SET utf8mb4;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        """


MODELS_STATE = (
    "eJztmltz2jgUgP8Kw1N2ptsxxjf2jQSyZZvATkJ2O206HlmWwYMtu7LchOnw31cSNr5gCE"
    "6XxGnywphzEdJ3ZPmcY360/cBGXvR+4OIZBd7iJkKk/UfrRxsDH7GLSv27VhuEYablAgos"
    "TzjYiaUZM1OhAlZECYCUaR3gRYiJbBRB4obUDTD3uY17itFLP3VVNm5jTe7qt7FhaAYfww"
    "4gG4QNvd9cA3LnNlZ1w+JOMXa/xcikwQzRuVjXl69M7GIb3aMo/RouTMdFnl1YtmvzAYTc"
    "pMtQyEaYngtDPh/LhIEX+zgzDpd0HuCNtYspl84QRgRQxIenJOaLx7HnJbRSHuuZZibrKe"
    "Z8bOSA2OMIuXcVQQV1LYZEldFoUCaW+MAA80iwmUVisTP+i7/LHUVXjK6mGMxEzGoj0Vfr"
    "pWYc1o6CxnjaXgk9oGBtIZBmDNmiAlwF8mwOSDXJnEsJJ5t4GWcK7zg8d20xVZUdTluSmM"
    "SQ+B61oHYgcR/cmx5iN8icfVWlPXj/6V+dfehfnajSb3zsgN1A6/trnGhkoeIRyIgHIaoJ"
    "PPNoLG9HkFa7h+/rI1PGLlyI6xqc8z6PIp1w3IBOTTLS2dn6EOrCial1VSbpOdJj4HakQ+"
    "gyq514ha7IF3xnJwoxY+JtE56i+x2HcNGrUYzVXldhnxJ0bq4uDsO8h+p0+GnKB/Gj6JuX"
    "h3ly2f8kOPvLRHMxGf+Zmufgn11MTsvMIURRxB6VC4RrUS/5/T+nyM+ANyzL4c9BhPgpjR"
    "h4XVZgM6kT5BAUzetj33J8fu7q+jhRLan53NF96BJkArrNfMBwUddH1dwLjiXmduL5Pr1o"
    "xs5ncgfyyOgdh8fH0biNo/x8ZEaXw+tp//LvQngG/emQ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